package com.cloud.core.app;

import android.app.Application;
import android.content.Context;

import androidx.multidex.MultiDex;

import com.cloud.core.multistate.EmptyAdapter;
import com.cloud.core.multistate.ErrorAdapter;
import com.cloud.core.multistate.LoadingAdapter;
import com.dylanc.loadinghelper.LoadingHelper;
import com.dylanc.loadinghelper.ViewType;

import kotlin.Unit;

/**
 * Created by Tanghaibo
 * 2018/3/21
 * description: Application类
 */

public abstract class BaseApplication extends Application {

    private static BaseApplication mApplication;

    @Override
    public void onCreate() {
        super.onCreate();
        mApplication = this;

        LoadingHelper.setDefaultAdapterPool(adapterPool -> {
            adapterPool.register(ViewType.LOADING, new LoadingAdapter());
            adapterPool.register(ViewType.ERROR, new ErrorAdapter());
            adapterPool.register(ViewType.EMPTY, new EmptyAdapter());
            return Unit.INSTANCE;
        });
    }

    public synchronized static BaseApplication getInstance() {
        return mApplication;
    }

    @Override
    protected void attachBaseContext(Context base) {
        super.attachBaseContext(base);
        //方法数超过分包
        MultiDex.install(this);
    }
}
